<template>
  <div class="message" @click="cancelBadge">
    <el-popover placement="bottom" :width="310" trigger="click">
      <template #reference>
        <el-badge :value="state.messageCount" :max="99" :show-zero="false" class="item">
          <i :class="'iconfont icon-xiaoxi'" class="toolBar-icon"></i>
        </el-badge>
      </template>
      <el-tabs v-model="activeName">
        <template v-for="msgItem in state.messageConfig">
          <el-tab-pane :label="`${msgItem.title}(${msgItem.msgList.length})`" :name="msgItem.name">
            <div class="message-list" v-if="msgItem.msgList.length" :key="msgItem.id">
              <div class="message-item" v-for="item in msgItem.msgList" :key="item.id">
                <img :src="item.img" alt="" class="message-icon" />
                <div class="message-content">
                  <span class="message-title mle">{{ item.title }}</span>
                  <span class="message-date">{{ item.date }}</span>
                </div>
              </div>
            </div>
            <div class="message-empty" v-else>
              <img src="@/assets/images/notData.png" alt="notData" />
              <div>暂无消息</div>
            </div>
          </el-tab-pane>
        </template>
        <!-- <el-tab-pane label="通知(5)" name="first">
          <div class="message-list">
            <div class="message-item">
              <img src="@/assets/images/msg01.png" alt="" class="message-icon" />
              <div class="message-content">
                <span class="message-title">一键三连 Admin 🧡</span>
                <span class="message-date">一分钟前</span>
              </div>
            </div>
            <div class="message-item">
              <img src="@/assets/images/msg02.png" alt="" class="message-icon" />
              <div class="message-content">
                <span class="message-title">一键三连 Admin 💙</span>
                <span class="message-date">一小时前</span>
              </div>
            </div>
            <div class="message-item">
              <img src="@/assets/images/msg03.png" alt="" class="message-icon" />
              <div class="message-content">
                <span class="message-title">一键三连 Admin 💚</span>
                <span class="message-date">半天前</span>
              </div>
            </div>
            <div class="message-item">
              <img src="@/assets/images/msg04.png" alt="" class="message-icon" />
              <div class="message-content">
                <span class="message-title">一键三连 Admin 💜</span>
                <span class="message-date">一星期前</span>
              </div>
            </div>
            <div class="message-item">
              <img src="@/assets/images/msg05.png" alt="" class="message-icon" />
              <div class="message-content">
                <span class="message-title">一键三连 Admin 💛</span>
                <span class="message-date">一个月前</span>
              </div>
            </div>
          </div>
        </el-tab-pane>
        <el-tab-pane label="消息(0)" name="second">
          <div class="message-empty">
            <img src="@/assets/images/notData.png" alt="notData" />
            <div>暂无消息</div>
          </div>
        </el-tab-pane>
        <el-tab-pane label="待办(0)" name="third">
          <div class="message-empty">
            <img src="@/assets/images/notData.png" alt="notData" />
            <div>暂无待办</div>
          </div>
        </el-tab-pane> -->
      </el-tabs>
    </el-popover>
  </div>
</template>

<script setup lang="ts">
import { reactive, ref } from "vue";
const activeName = ref("first");
const state = reactive({
  messageCount: 5,
  messageConfig: [
    {
      id: 1,
      title: "通知",
      name: "first",
      msgList: [
        { id: 1, title: "一键三连 Admin 🧡", date: "一分钟前", img: new URL("@/assets/images/msg01.png", import.meta.url).href },
        { id: 2, title: "一键三连 Admin 💙", date: "一小时前", img: new URL("@/assets/images/msg02.png", import.meta.url).href },
        { id: 3, title: "一键三连 Admin 💚", date: "半天前", img: new URL("@/assets/images/msg03.png", import.meta.url).href },
        { id: 4, title: "一键三连 Admin 💜", date: "一星期前", img: new URL("@/assets/images/msg04.png", import.meta.url).href },
        { id: 5, title: "一键三连 Admin 💛", date: "一个月前", img: new URL("@/assets/images/msg05.png", import.meta.url).href }
      ]
    },
    {
      id: 2,
      title: "消息",
      name: "second",
      msgList: []
    },
    {
      id: 3,
      title: "待办",
      name: "third",
      msgList: []
    },
    {
      id: 4,
      title: "进度",
      name: "four",
      msgList: []
    }
  ]
});

const cancelBadge = () => {
  state.messageCount = 0;
};
</script>

<style scoped lang="scss">
.message-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 260px;
  line-height: 45px;
}
.message-list {
  display: flex;
  flex-direction: column;
  max-height: 260px;
  overflow-y: auto;
  .message-item {
    display: flex;
    align-items: center;
    padding: 20px 0;
    border-bottom: 1px solid var(--el-border-color-light);
    cursor: pointer;
    &:last-child {
      border: none;
    }
    .message-icon {
      width: 40px;
      height: 40px;
      margin: 0 20px 0 5px;
    }
    .message-content {
      display: flex;
      flex-direction: column;
      .message-title {
        margin-bottom: 5px;
      }
      .message-date {
        font-size: 12px;
        color: var(--el-text-color-secondary);
      }
    }
  }
}
</style>
